package com.yx.changdao.common.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * 脱敏工具类
 *
 * @author zcz
 * @date 2020-5-6
 */
public class DesensitizationUtils {

    /**
     * 手机号码前3后4脱敏
     * @param mobile
     * @return
     */
    public static String mobileEncrypt(String mobile) {
        if (StringUtils.isEmpty(mobile) || (mobile.length() != 11)) {
            return mobile;
        }
        return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }

    /**
     * 身份证前10后2脱敏
     * @param id
     * @return
     */
    public static String idEncrypt(String id) {
        if (StringUtils.isEmpty(id) || (id.length() < 8)) {
            return id;
        }
        return id.replaceAll("(?<=\\w{10})\\w(?=\\w{2})", "*");
    }

}

